define(["validate"], function() {
	return {
		title: ['<a href="user.html">个人中心</a>', "修改登录密码"],
		init: function(content) {
			let form = content.find("form");
			$.get(
				"user/login-user.do",
				function(data) {
					$.each(data, function(name, value) {
						content.find("[name='" + name + "']").val(value);
					});
					validateForm();
				}, "json"
			);

			let validateForm = function() {
				form.bootstrapValidator({
					//container: 'tooltip',
					//					feedbackIcons: {
					//						valid: 'glyphicon glyphicon-ok',
					//						invalid: 'glyphicon glyphicon-remove',
					//						validating: 'glyphicon glyphicon-refresh'
					//					},
					fields: {
						oldUserPwd: {
							validators: {
								notEmpty: {
									message: "旧密码不能为空"
								}
							}
						},
						newUserPwd: {
							validators: {
								notEmpty: {
									message: "新密码不能为空"
								},
								regexp: {
									enabled: true,
									regexp: /^.{3,20}$/i,
									message: '密码必须为3-20个字符组成'
								},
								identical: {
									field: 'newUserPwd1',
									message: '两次输入的密码不一致'
								},
								different: {
									field: 'userName',
									message: '密码不能和用户名一样'
								}
							}
						},
						newUserPwd1: {
							validators: {
								identical: {
									field: 'newUserPwd',
									message: '两次输入的密码不一致'
								}
							}
						}
					}
				}).on("success.form.bv", function() {
					$.post(
						"user/my-pwd.do",
						form.serializeArray(),
						function(data) {
							if(data.ok) {
								toastr.success("修改密码成功");

							} else {
								toastr.error(data.message);
							}
						}, "json"
					);
					return false;
				});
			}

		}
	}
});